<?xml version="1.0" encoding="iso-8859-1"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "DTD/xhtml1-strict.dtd">
<html><head><title>QFile Class Reference</title><style>h3.fn,span.fn { margin-left: 1cm; text-indent: -1cm }
a:link { color: #004faf; text-decoration: none }
a:visited { color: #672967; text-decoration: none }
td.postheader { font-family: sans-serif }
tr.address { font-family: sans-serif }
body { background: #ffffff; color: black; }
</style></head><body><table border="0" cellpadding="0" cellspacing="0" width="100%"><tr /><td align="left" valign="top" width="32"><img align="left" border="0" height="32" src="images/rb-logo.png" width="32" /></td><td width="1">&#160;&#160;</td><td class="postheader" valign="center"><a href="index.html"><font color="#004faf">Home</font></a>&#160;&#183; <a href="classes.html"><font color="#004faf">All Classes</font></a>&#160;&#183; <a href="modules.html"><font color="#004faf">Modules</font></a></td></table><h1 align="center">QFile Class Reference<br /><sup><sup>[<a href="qtcore.html">QtCore</a> module]</sup></sup></h1><p>The QFile class provides an interface for reading from and
writing to files. <a href="#details">More...</a></p>

<p>Inherits <a href="qiodevice.html">QIODevice</a>.</p><p>Inherited by <a href="qtemporaryfile.html">QTemporaryFile</a>.</p><h3>Types</h3><ul><li><div class="fn" />enum <b><a href="qfile.html#FileError-enum">FileError</a></b> { NoError, ReadError, WriteError, FatalError, ..., CopyError }</li><li><div class="fn" />enum <b><a href="qfile.html#MemoryMapFlags-enum">MemoryMapFlags</a></b> { NoOptions }</li><li><div class="fn" />enum <b><a href="qfile.html#Permission-enum">Permission</a></b> { ReadOwner, WriteOwner, ExeOwner, ReadUser, ..., ExeOther }</li><li><div class="fn" />class <b><a href="qfile-permissions.html">Permissions</a></b></li></ul><h3>Methods</h3><ul><li><div class="fn" /><b><a href="qfile.html#QFile">__init__</a></b> (<i>self</i>)</li><li><div class="fn" /><b><a href="qfile.html#QFile-2">__init__</a></b> (<i>self</i>, QString&#160;<i>name</i>)</li><li><div class="fn" /><b><a href="qfile.html#QFile-3">__init__</a></b> (<i>self</i>, QObject&#160;<i>parent</i>)</li><li><div class="fn" /><b><a href="qfile.html#QFile-4">__init__</a></b> (<i>self</i>, QString&#160;<i>name</i>, QObject&#160;<i>parent</i>)</li><li><div class="fn" />bool <b><a href="qfile.html#atEnd">atEnd</a></b> (<i>self</i>)</li><li><div class="fn" /><b><a href="qfile.html#close">close</a></b> (<i>self</i>)</li><li><div class="fn" />bool <b><a href="qfile.html#copy">copy</a></b> (<i>self</i>, QString&#160;<i>newName</i>)</li><li><div class="fn" />FileError <b><a href="qfile.html#error">error</a></b> (<i>self</i>)</li><li><div class="fn" />bool <b><a href="qfile.html#exists">exists</a></b> (<i>self</i>)</li><li><div class="fn" />QAbstractFileEngine <b><a href="qfile.html#fileEngine">fileEngine</a></b> (<i>self</i>)</li><li><div class="fn" />QString <b><a href="qfile.html#fileName">fileName</a></b> (<i>self</i>)</li><li><div class="fn" />bool <b><a href="qfile.html#flush">flush</a></b> (<i>self</i>)</li><li><div class="fn" />int <b><a href="qfile.html#handle">handle</a></b> (<i>self</i>)</li><li><div class="fn" />bool <b><a href="qfile.html#isSequential">isSequential</a></b> (<i>self</i>)</li><li><div class="fn" />bool <b><a href="qfile.html#link">link</a></b> (<i>self</i>, QString&#160;<i>newName</i>)</li><li><div class="fn" />sip.voidptr <b><a href="qfile.html#map">map</a></b> (<i>self</i>, int&#160;<i>offset</i>, int&#160;<i>size</i>, MemoryMapFlags&#160;<i>flags</i>&#160;=&#160;QFile.NoOptions)</li><li><div class="fn" />bool <b><a href="qfile.html#open">open</a></b> (<i>self</i>, QIODevice.OpenMode&#160;<i>flags</i>)</li><li><div class="fn" />bool <b><a href="qfile.html#open-2">open</a></b> (<i>self</i>, int&#160;<i>fd</i>, QIODevice.OpenMode&#160;<i>flags</i>)</li><li><div class="fn" />Permissions <b><a href="qfile.html#permissions">permissions</a></b> (<i>self</i>)</li><li><div class="fn" />int <b><a href="qfile.html#pos">pos</a></b> (<i>self</i>)</li><li><div class="fn" />str <b><a href="qfile.html#readData">readData</a></b> (<i>self</i>, int&#160;<i>maxlen</i>)</li><li><div class="fn" />str <b><a href="qfile.html#readLineData">readLineData</a></b> (<i>self</i>, int&#160;<i>maxlen</i>)</li><li><div class="fn" />QString <b><a href="qfile.html#readLink">readLink</a></b> (<i>self</i>)</li><li><div class="fn" />bool <b><a href="qfile.html#remove">remove</a></b> (<i>self</i>)</li><li><div class="fn" />bool <b><a href="qfile.html#rename">rename</a></b> (<i>self</i>, QString&#160;<i>newName</i>)</li><li><div class="fn" />bool <b><a href="qfile.html#resize">resize</a></b> (<i>self</i>, int&#160;<i>sz</i>)</li><li><div class="fn" />bool <b><a href="qfile.html#seek">seek</a></b> (<i>self</i>, int&#160;<i>offset</i>)</li><li><div class="fn" /><b><a href="qfile.html#setFileName">setFileName</a></b> (<i>self</i>, QString&#160;<i>name</i>)</li><li><div class="fn" />bool <b><a href="qfile.html#setPermissions">setPermissions</a></b> (<i>self</i>, Permissions&#160;<i>permissionSpec</i>)</li><li><div class="fn" />int <b><a href="qfile.html#size">size</a></b> (<i>self</i>)</li><li><div class="fn" />QString <b><a href="qfile.html#symLinkTarget">symLinkTarget</a></b> (<i>self</i>)</li><li><div class="fn" />bool <b><a href="qfile.html#unmap">unmap</a></b> (<i>self</i>, sip.voidptr&#160;<i>address</i>)</li><li><div class="fn" /><b><a href="qfile.html#unsetError">unsetError</a></b> (<i>self</i>)</li><li><div class="fn" />int <b><a href="qfile.html#writeData">writeData</a></b> (<i>self</i>, str&#160;<i>data</i>)</li></ul><h3>Static Methods</h3><ul><li><div class="fn" />bool <b><a href="qfile.html#copy-2">copy</a></b> (QString&#160;<i>fileName</i>, QString&#160;<i>newName</i>)</li><li><div class="fn" />QString <b><a href="qfile.html#decodeName">decodeName</a></b> (QByteArray&#160;<i>localFileName</i>)</li><li><div class="fn" />QString <b><a href="qfile.html#decodeName-2">decodeName</a></b> (str&#160;<i>localFileName</i>)</li><li><div class="fn" />QByteArray <b><a href="qfile.html#encodeName">encodeName</a></b> (QString&#160;<i>fileName</i>)</li><li><div class="fn" />bool <b><a href="qfile.html#exists-2">exists</a></b> (QString&#160;<i>fileName</i>)</li><li><div class="fn" />bool <b><a href="qfile.html#link-2">link</a></b> (QString&#160;<i>oldname</i>, QString&#160;<i>newName</i>)</li><li><div class="fn" />Permissions <b><a href="qfile.html#permissions-2">permissions</a></b> (QString&#160;<i>filename</i>)</li><li><div class="fn" />QString <b><a href="qfile.html#readLink-2">readLink</a></b> (QString&#160;<i>fileName</i>)</li><li><div class="fn" />bool <b><a href="qfile.html#remove-2">remove</a></b> (QString&#160;<i>fileName</i>)</li><li><div class="fn" />bool <b><a href="qfile.html#rename-2">rename</a></b> (QString&#160;<i>oldName</i>, QString&#160;<i>newName</i>)</li><li><div class="fn" />bool <b><a href="qfile.html#resize-2">resize</a></b> (QString&#160;<i>filename</i>, int&#160;<i>sz</i>)</li><li><div class="fn" />bool <b><a href="qfile.html#setPermissions-2">setPermissions</a></b> (QString&#160;<i>filename</i>, Permissions&#160;<i>permissionSpec</i>)</li><li><div class="fn" />QString <b><a href="qfile.html#symLinkTarget-2">symLinkTarget</a></b> (QString&#160;<i>fileName</i>)</li></ul><a name="details" /><hr /><h2>Detailed Description</h2><p>The QFile class provides an interface for reading from and
writing to files.</p>
<p>QFile is an I/O device for reading and writing text and binary
files and <a href="resources.html">resources</a>. A QFile may be
used by itself or, more conveniently, with a <a href="qtextstream.html">QTextStream</a> or <a href="qdatastream.html">QDataStream</a>.</p>
<p>The file name is usually passed in the constructor, but it can
be set at any time using <a href="qfile.html#setFileName">setFileName</a>(). QFile expects the file
separator to be '/' regardless of operating system. The use of
other separators (e.g., '\') is not supported.</p>
<p>You can check for a file's existence using <a href="qfile.html#exists">exists</a>(), and remove a file using <a href="qfile.html#remove">remove</a>(). (More advanced file system
related operations are provided by <a href="qfileinfo.html">QFileInfo</a> and <a href="qdir.html">QDir</a>.)</p>
<p>The file is opened with <a href="qfile.html#open">open</a>(),
closed with <a href="qfile.html#close">close</a>(), and flushed
with <a href="qfile.html#flush">flush</a>(). Data is usually read
and written using <a href="qdatastream.html">QDataStream</a> or
<a href="qtextstream.html">QTextStream</a>, but you can also call
the <a href="qiodevice.html">QIODevice</a>-inherited functions
<a href="qiodevice.html#read">read</a>(), <a href="qiodevice.html#readLine">readLine</a>(), <a href="qiodevice.html#readAll">readAll</a>(), <a href="qiodevice.html#write">write</a>(). QFile also inherits <a href="qiodevice.html#getChar">getChar</a>(), <a href="qiodevice.html#putChar">putChar</a>(), and <a href="qiodevice.html#ungetChar">ungetChar</a>(), which work one
character at a time.</p>
<p>The size of the file is returned by <a href="qfile.html#size">size</a>(). You can get the current file position
using <a href="qfile.html#pos">pos</a>(), or move to a new file
position using <a href="qfile.html#seek">seek</a>(). If you've
reached the end of the file, <a href="qfile.html#atEnd">atEnd</a>()
returns true.</p>
<a id="reading-files-directly" name="reading-files-directly" />
<h3>Reading Files Directly</h3>
<p>The following example reads a text file line by line:</p>
<pre class="cpp">
     <span class="type">QFile</span> file(<span class="string">"in.txt"</span>);
     <span class="keyword">if</span> (<span class="operator">!</span>file<span class="operator">.</span>open(<span class="type"><a href="qiodevice.html">QIODevice</a></span><span class="operator">.</span>ReadOnly <span class="operator">|</span> <span class="type"><a href="qiodevice.html">QIODevice</a></span><span class="operator">.</span>Text))
         <span class="keyword">return</span>;

     <span class="keyword">while</span> (<span class="operator">!</span>file<span class="operator">.</span>atEnd()) {
         <span class="type"><a href="qbytearray.html">QByteArray</a></span> line <span class="operator">=</span> file<span class="operator">.</span>readLine();
         process_line(line);
     }
</pre>
<p>The <a href="qiodevice.html#OpenModeFlag-enum">QIODevice.Text</a> flag passed
to <a href="qfile.html#open">open</a>() tells Qt to convert
Windows-style line terminators ("\r\n") into C++-style terminators
("\n"). By default, QFile assumes binary, i.e. it doesn't perform
any conversion on the bytes stored in the file.</p>
<a id="using-streams-to-read-files" name="using-streams-to-read-files" />
<h3>Using Streams to Read Files</h3>
<p>The next example uses <a href="qtextstream.html">QTextStream</a>
to read a text file line by line:</p>
<pre class="cpp">
     <span class="type">QFile</span> file(<span class="string">"in.txt"</span>);
     <span class="keyword">if</span> (<span class="operator">!</span>file<span class="operator">.</span>open(<span class="type"><a href="qiodevice.html">QIODevice</a></span><span class="operator">.</span>ReadOnly <span class="operator">|</span> <span class="type"><a href="qiodevice.html">QIODevice</a></span><span class="operator">.</span>Text))
         <span class="keyword">return</span>;

     <span class="type"><a href="qtextstream.html">QTextStream</a></span> in(<span class="operator">&amp;</span>file);
     <span class="keyword">while</span> (<span class="operator">!</span>in<span class="operator">.</span>atEnd()) {
         <span class="type"><a href="qstring.html">QString</a></span> line <span class="operator">=</span> in<span class="operator">.</span>readLine();
         process_line(line);
     }
</pre>
<p><a href="qtextstream.html">QTextStream</a> takes care of
converting the 8-bit data stored on disk into a 16-bit Unicode
<a href="qstring.html">QString</a>. By default, it assumes that the
user system's local 8-bit encoding is used (e.g., ISO 8859-1 for
most of Europe; see <a href="qtextcodec.html#codecForLocale">QTextCodec.codecForLocale</a>()
for details). This can be changed using setCodec().</p>
<p>To write text, we can use operator&lt;&lt;(), which is
overloaded to take a <a href="qtextstream.html">QTextStream</a> on
the left and various data types (including <a href="qstring.html">QString</a>) on the right:</p>
<pre class="cpp">
     <span class="type">QFile</span> file(<span class="string">"out.txt"</span>);
     <span class="keyword">if</span> (<span class="operator">!</span>file<span class="operator">.</span>open(<span class="type"><a href="qiodevice.html">QIODevice</a></span><span class="operator">.</span>WriteOnly <span class="operator">|</span> <span class="type"><a href="qiodevice.html">QIODevice</a></span><span class="operator">.</span>Text))
         <span class="keyword">return</span>;

     <span class="type"><a href="qtextstream.html">QTextStream</a></span> out(<span class="operator">&amp;</span>file);
     out <span class="operator">&lt;</span><span class="operator">&lt;</span> <span class="string">"The magic number is: "</span> <span class="operator">&lt;</span><span class="operator">&lt;</span> <span class="number">49</span> <span class="operator">&lt;</span><span class="operator">&lt;</span> <span class="string">"\n"</span>;
</pre>
<p><a href="qdatastream.html">QDataStream</a> is similar, in that
you can use operator&lt;&lt;() to write data and operator&gt;&gt;()
to read it back. See the class documentation for details.</p>
<p>When you use QFile, <a href="qfileinfo.html">QFileInfo</a>, and
<a href="qdir.html">QDir</a> to access the file system with Qt, you
can use Unicode file names. On Unix, these file names are converted
to an 8-bit encoding. If you want to use standard C++ APIs
(<tt>&lt;cstdio&gt;</tt> or <tt>&lt;iostream&gt;</tt>) or
platform-specific APIs to access files instead of QFile, you can
use the <a href="qfile.html#encodeName">encodeName</a>() and
<a href="qfile.html#decodeName">decodeName</a>() functions to
convert between Unicode file names and 8-bit file names.</p>
<p>On Unix, there are some special system files (e.g. in
<tt>/proc</tt>) for which <a href="qfile.html#size">size</a>() will
always return 0, yet you may still be able to read more data from
such a file; the data is generated in direct response to you
calling <a href="qiodevice.html#read">read</a>(). In this case,
however, you cannot use <a href="qfile.html#atEnd">atEnd</a>() to
determine if there is more data to read (since <a href="qfile.html#atEnd">atEnd</a>() will return true for a file that
claims to have size 0). Instead, you should either call <a href="qiodevice.html#readAll">readAll</a>(), or call <a href="qiodevice.html#read">read</a>() or <a href="qiodevice.html#readLine">readLine</a>() repeatedly until no more
data can be read. The next example uses <a href="qtextstream.html">QTextStream</a> to read <tt>/proc/modules</tt>
line by line:</p>
<pre class="cpp">
     <span class="type">QFile</span> file(<span class="string">"/proc/modules"</span>);
     <span class="keyword">if</span> (<span class="operator">!</span>file<span class="operator">.</span>open(<span class="type"><a href="qiodevice.html">QIODevice</a></span><span class="operator">.</span>ReadOnly <span class="operator">|</span> <span class="type"><a href="qiodevice.html">QIODevice</a></span><span class="operator">.</span>Text))
         <span class="keyword">return</span>;

     <span class="type"><a href="qtextstream.html">QTextStream</a></span> in(<span class="operator">&amp;</span>file);
     <span class="type"><a href="qstring.html">QString</a></span> line <span class="operator">=</span> in<span class="operator">.</span>readLine();
     <span class="keyword">while</span> (<span class="operator">!</span>line<span class="operator">.</span>isNull()) {
         process_line(line);
         line <span class="operator">=</span> in<span class="operator">.</span>readLine();
     }
</pre>
<a id="signals" name="signals" />
<h3>Signals</h3>
<p>Unlike other <a href="qiodevice.html">QIODevice</a>
implementations, such as <a href="qtcpsocket.html">QTcpSocket</a>,
QFile does not emit the <a href="qiodevice.html#aboutToClose">aboutToClose</a>(), <a href="qiodevice.html#bytesWritten">bytesWritten</a>(), or <a href="qiodevice.html#readyRead">readyRead</a>() signals. This
implementation detail means that QFile is not suitable for reading
and writing certain types of files, such as device files on Unix
platforms.</p>
<a id="platform-specific-issues" name="platform-specific-issues" />
<h3>Platform Specific Issues</h3>
<p>File permissions are handled differently on Linux/Mac OS X and
Windows. In a non <a href="qiodevice.html#isWritable">writable</a>
directory on Linux, files cannot be created. This is not always the
case on Windows, where, for instance, the 'My Documents' directory
usually is not writable, but it is still possible to create files
in it.</p>
<hr /><h2>Type Documentation</h2><h3 class="fn"><a name="FileError-enum" />QFile.FileError</h3><p>This enum describes the errors that may be returned by the
<a href="qfile.html#error">error</a>() function.</p>
<table class="valuelist">
<tr class="odd" valign="top">
<th class="tblConst">Constant</th>
<th class="tblval">Value</th>
<th class="tbldscr">Description</th>
</tr>
<tr>
<td class="topAlign"><tt>QFile.NoError</tt></td>
<td class="topAlign"><tt>0</tt></td>
<td class="topAlign">No error occurred.</td>
</tr>
<tr>
<td class="topAlign"><tt>QFile.ReadError</tt></td>
<td class="topAlign"><tt>1</tt></td>
<td class="topAlign">An error occurred when reading from the
file.</td>
</tr>
<tr>
<td class="topAlign"><tt>QFile.WriteError</tt></td>
<td class="topAlign"><tt>2</tt></td>
<td class="topAlign">An error occurred when writing to the
file.</td>
</tr>
<tr>
<td class="topAlign"><tt>QFile.FatalError</tt></td>
<td class="topAlign"><tt>3</tt></td>
<td class="topAlign">A fatal error occurred.</td>
</tr>
<tr>
<td class="topAlign"><tt>QFile.ResourceError</tt></td>
<td class="topAlign"><tt>4</tt></td>
<td class="topAlign">&#160;</td>
</tr>
<tr>
<td class="topAlign"><tt>QFile.OpenError</tt></td>
<td class="topAlign"><tt>5</tt></td>
<td class="topAlign">The file could not be opened.</td>
</tr>
<tr>
<td class="topAlign"><tt>QFile.AbortError</tt></td>
<td class="topAlign"><tt>6</tt></td>
<td class="topAlign">The operation was aborted.</td>
</tr>
<tr>
<td class="topAlign"><tt>QFile.TimeOutError</tt></td>
<td class="topAlign"><tt>7</tt></td>
<td class="topAlign">A timeout occurred.</td>
</tr>
<tr>
<td class="topAlign"><tt>QFile.UnspecifiedError</tt></td>
<td class="topAlign"><tt>8</tt></td>
<td class="topAlign">An unspecified error occurred.</td>
</tr>
<tr>
<td class="topAlign"><tt>QFile.RemoveError</tt></td>
<td class="topAlign"><tt>9</tt></td>
<td class="topAlign">The file could not be removed.</td>
</tr>
<tr>
<td class="topAlign"><tt>QFile.RenameError</tt></td>
<td class="topAlign"><tt>10</tt></td>
<td class="topAlign">The file could not be renamed.</td>
</tr>
<tr>
<td class="topAlign"><tt>QFile.PositionError</tt></td>
<td class="topAlign"><tt>11</tt></td>
<td class="topAlign">The position in the file could not be
changed.</td>
</tr>
<tr>
<td class="topAlign"><tt>QFile.ResizeError</tt></td>
<td class="topAlign"><tt>12</tt></td>
<td class="topAlign">The file could not be resized.</td>
</tr>
<tr>
<td class="topAlign"><tt>QFile.PermissionsError</tt></td>
<td class="topAlign"><tt>13</tt></td>
<td class="topAlign">The file could not be accessed.</td>
</tr>
<tr>
<td class="topAlign"><tt>QFile.CopyError</tt></td>
<td class="topAlign"><tt>14</tt></td>
<td class="topAlign">The file could not be copied.</td>
</tr>
</table>


<h3 class="fn"><a name="MemoryMapFlags-enum" />QFile.MemoryMapFlags</h3><p>This enum describes special options that may be used by the
<a href="qfile.html#map">map</a>() function.</p>
<table class="valuelist">
<tr class="odd" valign="top">
<th class="tblConst">Constant</th>
<th class="tblval">Value</th>
<th class="tbldscr">Description</th>
</tr>
<tr>
<td class="topAlign"><tt>QFile.NoOptions</tt></td>
<td class="topAlign"><tt>0</tt></td>
<td class="topAlign">No options.</td>
</tr>
</table>
<p>This enum was introduced or modified in Qt 4.4.</p>


<h3 class="fn"><a name="Permission-enum" />QFile.Permission</h3><p>This enum is used by the permission() function to report the
permissions and ownership of a file. The values may be OR-ed
together to test multiple permissions and ownership values.</p>
<table class="valuelist">
<tr class="odd" valign="top">
<th class="tblConst">Constant</th>
<th class="tblval">Value</th>
<th class="tbldscr">Description</th>
</tr>
<tr>
<td class="topAlign"><tt>QFile.ReadOwner</tt></td>
<td class="topAlign"><tt>0x4000</tt></td>
<td class="topAlign">The file is readable by the owner of the
file.</td>
</tr>
<tr>
<td class="topAlign"><tt>QFile.WriteOwner</tt></td>
<td class="topAlign"><tt>0x2000</tt></td>
<td class="topAlign">The file is writable by the owner of the
file.</td>
</tr>
<tr>
<td class="topAlign"><tt>QFile.ExeOwner</tt></td>
<td class="topAlign"><tt>0x1000</tt></td>
<td class="topAlign">The file is executable by the owner of the
file.</td>
</tr>
<tr>
<td class="topAlign"><tt>QFile.ReadUser</tt></td>
<td class="topAlign"><tt>0x0400</tt></td>
<td class="topAlign">The file is readable by the user.</td>
</tr>
<tr>
<td class="topAlign"><tt>QFile.WriteUser</tt></td>
<td class="topAlign"><tt>0x0200</tt></td>
<td class="topAlign">The file is writable by the user.</td>
</tr>
<tr>
<td class="topAlign"><tt>QFile.ExeUser</tt></td>
<td class="topAlign"><tt>0x0100</tt></td>
<td class="topAlign">The file is executable by the user.</td>
</tr>
<tr>
<td class="topAlign"><tt>QFile.ReadGroup</tt></td>
<td class="topAlign"><tt>0x0040</tt></td>
<td class="topAlign">The file is readable by the group.</td>
</tr>
<tr>
<td class="topAlign"><tt>QFile.WriteGroup</tt></td>
<td class="topAlign"><tt>0x0020</tt></td>
<td class="topAlign">The file is writable by the group.</td>
</tr>
<tr>
<td class="topAlign"><tt>QFile.ExeGroup</tt></td>
<td class="topAlign"><tt>0x0010</tt></td>
<td class="topAlign">The file is executable by the group.</td>
</tr>
<tr>
<td class="topAlign"><tt>QFile.ReadOther</tt></td>
<td class="topAlign"><tt>0x0004</tt></td>
<td class="topAlign">The file is readable by anyone.</td>
</tr>
<tr>
<td class="topAlign"><tt>QFile.WriteOther</tt></td>
<td class="topAlign"><tt>0x0002</tt></td>
<td class="topAlign">The file is writable by anyone.</td>
</tr>
<tr>
<td class="topAlign"><tt>QFile.ExeOther</tt></td>
<td class="topAlign"><tt>0x0001</tt></td>
<td class="topAlign">The file is executable by anyone.</td>
</tr>
</table>
<p><b>Warning:</b> Because of differences in the platforms
supported by Qt, the semantics of ReadUser, WriteUser and ExeUser
are platform-dependent: On Unix, the rights of the owner of the
file are returned and on Windows the rights of the current user are
returned. This behavior might change in a future Qt version.</p>
<p>Note that Qt does not by default check for permissions on NTFS
file systems, as this may decrease the performance of file handling
considerably. It is possible to force permission checking on NTFS
by including the following code in your source:</p>
<pre class="cpp">
 <span class="keyword">extern</span> Q_CORE_EXPORT <span class="type">int</span> qt_ntfs_permission_lookup;
</pre>
<p>Permission checking is then turned on and off by incrementing
and decrementing <tt>qt_ntfs_permission_lookup</tt> by 1.</p>
<pre class="cpp">
 qt_ntfs_permission_lookup<span class="operator">+</span><span class="operator">+</span>; <span class="comment">// turn checking on</span>
 qt_ntfs_permission_lookup<span class="operator">-</span><span class="operator">-</span>; <span class="comment">// turn it off again</span>
</pre>
<p>The Permissions type is a typedef for <a href="qflags.html">QFlags</a>&lt;Permission&gt;. It stores an OR
combination of Permission values.</p>


<hr /><h2>Method Documentation</h2><h3 class="fn"><a name="QFile" />QFile.__init__ (<i>self</i>)</h3><p>Constructs a new file object to represent the file with the
given <i>name</i>.</p>


<h3 class="fn"><a name="QFile-2" />QFile.__init__ (<i>self</i>, QString&#160;<i>name</i>)</h3><h3 class="fn"><a name="QFile-3" />QFile.__init__ (<i>self</i>, <a href="qobject.html">QObject</a>&#160;<i>parent</i>)</h3><p>The <i>parent</i> argument, if not None, causes <i>self</i> to be owned by Qt instead of PyQt.</p><p>Constructs a new file object with the given <i>parent</i>.</p>


<h3 class="fn"><a name="QFile-4" />QFile.__init__ (<i>self</i>, QString&#160;<i>name</i>, <a href="qobject.html">QObject</a>&#160;<i>parent</i>)</h3><p>The <i>parent</i> argument, if not None, causes <i>self</i> to be owned by Qt instead of PyQt.</p><p>Constructs a new file object with the given <i>parent</i> to
represent the file with the specified <i>name</i>.</p>


<h3 class="fn"><a name="atEnd" />bool QFile.atEnd (<i>self</i>)</h3><p>Reimplemented from <a href="qiodevice.html#atEnd">QIODevice.atEnd</a>().</p>
<p>Returns true if the end of the file has been reached; otherwise
returns false.</p>
<p>For regular empty files on Unix (e.g. those in <tt>/proc</tt>),
this function returns true, since the file system reports that the
size of such a file is 0. Therefore, you should not depend on
atEnd() when reading data from such a file, but rather call
<a href="qiodevice.html#read">read</a>() until no more data can be
read.</p>


<h3 class="fn"><a name="close" />QFile.close (<i>self</i>)</h3><p>Reimplemented from <a href="qiodevice.html#close">QIODevice.close</a>().</p>
<p>Calls <a href="qfile.html#flush">QFile.flush</a>() and closes
the file. Errors from flush are ignored.</p>
<p><b>See also</b> <a href="qiodevice.html#close">QIODevice.close</a>().</p>


<h3 class="fn"><a name="copy" />bool QFile.copy (<i>self</i>, QString&#160;<i>newName</i>)</h3><p>Copies the file currently specified by <a href="qfile.html#fileName">fileName</a>() to a file called
<i>newName</i>. Returns true if successful; otherwise returns
false.</p>
<p>Note that if a file with the name <i>newName</i> already exists,
copy() returns false (i.e. <a href="qfile.html">QFile</a> will not
overwrite it).</p>
<p>The source file is closed before it is copied.</p>
<p><b>See also</b> <a href="qfile.html#setFileName">setFileName</a>().</p>


<h3 class="fn"><a name="copy-2" />bool QFile.copy (QString&#160;<i>fileName</i>, QString&#160;<i>newName</i>)</h3><p>This is an overloaded function.</p>
<p>Copies the file <i>fileName</i> to <i>newName</i>. Returns true
if successful; otherwise returns false.</p>
<p>If a file with the name <i>newName</i> already exists, <a href="qfile.html#copy">copy</a>() returns false (i.e., <a href="qfile.html">QFile</a> will not overwrite it).</p>
<p><b>See also</b> <a href="qfile.html#rename">rename</a>().</p>


<h3 class="fn"><a name="decodeName" />QString QFile.decodeName (<a href="qbytearray.html">QByteArray</a>&#160;<i>localFileName</i>)</h3><p>This does the reverse of <a href="qfile.html#encodeName">QFile.encodeName</a>() using
<i>localFileName</i>.</p>
<p><b>See also</b> <a href="qfile.html#setDecodingFunction">setDecodingFunction</a>() and
<a href="qfile.html#encodeName">encodeName</a>().</p>


<h3 class="fn"><a name="decodeName-2" />QString QFile.decodeName (str&#160;<i>localFileName</i>)</h3><p>This is an overloaded function.</p>
<p>Returns the Unicode version of the given <i>localFileName</i>.
See <a href="qfile.html#encodeName">encodeName</a>() for
details.</p>


<h3 class="fn"><a name="encodeName" /><a href="qbytearray.html">QByteArray</a> QFile.encodeName (QString&#160;<i>fileName</i>)</h3><p>By default, this function converts <i>fileName</i> to the local
8-bit encoding determined by the user's locale. This is sufficient
for file names that the user chooses. File names hard-coded into
the application should only use 7-bit ASCII filename
characters.</p>
<p><b>See also</b> <a href="qfile.html#decodeName">decodeName</a>()
and <a href="qfile.html#setEncodingFunction">setEncodingFunction</a>().</p>


<h3 class="fn"><a name="error" /><a href="qfile.html#FileError-enum">FileError</a> QFile.error (<i>self</i>)</h3><p>Returns the file error status.</p>
<p>The I/O device status returns an error code. For example, if
<a href="qfile.html#open">open</a>() returns false, or a read/write
operation returns -1, this function can be called to find out the
reason why the operation failed.</p>
<p><b>See also</b> <a href="qfile.html#unsetError">unsetError</a>().</p>


<h3 class="fn"><a name="exists" />bool QFile.exists (<i>self</i>)</h3><p>Returns true if the file specified by <i>fileName</i> exists;
otherwise returns false.</p>


<h3 class="fn"><a name="exists-2" />bool QFile.exists (QString&#160;<i>fileName</i>)</h3><p>This is an overloaded function.</p>
<p>Returns true if the file specified by <a href="qfile.html#fileName">fileName</a>() exists; otherwise returns
false.</p>
<p><b>See also</b> <a href="qfile.html#fileName">fileName</a>() and
<a href="qfile.html#setFileName">setFileName</a>().</p>


<h3 class="fn"><a name="fileEngine" /><a href="qabstractfileengine.html">QAbstractFileEngine</a> QFile.fileEngine (<i>self</i>)</h3><h3 class="fn"><a name="fileName" />QString QFile.fileName (<i>self</i>)</h3><p>Returns the name set by <a href="qfile.html#setFileName">setFileName</a>() or to the <a href="qfile.html">QFile</a> constructors.</p>
<p><b>See also</b> <a href="qfile.html#setFileName">setFileName</a>() and <a href="qfileinfo.html#fileName">QFileInfo.fileName</a>().</p>


<h3 class="fn"><a name="flush" />bool QFile.flush (<i>self</i>)</h3><p>Flushes any buffered data to the file. Returns true if
successful; otherwise returns false.</p>


<h3 class="fn"><a name="handle" />int QFile.handle (<i>self</i>)</h3><p>Returns the file handle of the file.</p>
<p>This is a small positive integer, suitable for use with C
library functions such as fdopen() and fcntl(). On systems that use
file descriptors for sockets (i.e. Unix systems, but not Windows)
the handle can be used with <a href="qsocketnotifier.html">QSocketNotifier</a> as well.</p>
<p>If the file is not open, or there is an error, handle() returns
-1.</p>
<p>This function is not supported on Windows CE.</p>
<p>On Symbian, this function returns -1 if the file was opened
normally, as Symbian OS native file handles do not fit in an int,
and are incompatible with C library functions that the handle would
be used for. If the file was opened using the overloads that take
an open C library file handle / file descriptor, then this function
returns that same handle.</p>
<p><b>See also</b> <a href="qsocketnotifier.html">QSocketNotifier</a>.</p>


<h3 class="fn"><a name="isSequential" />bool QFile.isSequential (<i>self</i>)</h3><p>Reimplemented from <a href="qiodevice.html#isSequential">QIODevice.isSequential</a>().</p>
<p>Returns true if the file can only be manipulated sequentially;
otherwise returns false.</p>
<p>Most files support random-access, but some special files may
not.</p>
<p><b>See also</b> <a href="qiodevice.html#isSequential">QIODevice.isSequential</a>().</p>


<h3 class="fn"><a name="link" />bool QFile.link (<i>self</i>, QString&#160;<i>newName</i>)</h3><p>Creates a link named <i>linkName</i> that points to the file
currently specified by <a href="qfile.html#fileName">fileName</a>(). What a link is depends on the
underlying filesystem (be it a shortcut on Windows or a symbolic
link on Unix). Returns true if successful; otherwise returns
false.</p>
<p>This function will not overwrite an already existing entity in
the file system; in this case, <tt>link()</tt> will return false
and set <a href="qfile.html#error">error()</a> to return <a href="qfile.html#FileError-enum">RenameError</a>.</p>
<p><b>Note:</b> To create a valid link on Windows, <i>linkName</i>
must have a <tt>.lnk</tt> file extension.</p>
<p><b>Note:</b> Symbian filesystem does not support links.</p>
<p><b>See also</b> <a href="qfile.html#setFileName">setFileName</a>().</p>


<h3 class="fn"><a name="link-2" />bool QFile.link (QString&#160;<i>oldname</i>, QString&#160;<i>newName</i>)</h3><p>This is an overloaded function.</p>
<p>Creates a link named <i>linkName</i> that points to the file
<i>fileName</i>. What a link is depends on the underlying
filesystem (be it a shortcut on Windows or a symbolic link on
Unix). Returns true if successful; otherwise returns false.</p>
<p><b>See also</b> <a href="qfile.html#link">link</a>().</p>


<h3 class="fn"><a name="map" />sip.voidptr QFile.map (<i>self</i>, int&#160;<i>offset</i>, int&#160;<i>size</i>, <a href="qfile.html#MemoryMapFlags-enum">MemoryMapFlags</a>&#160;<i>flags</i>&#160;=&#160;QFile.NoOptions)</h3><p>Maps <i>size</i> bytes of the file into memory starting at
<i>offset</i>. A file should be open for a map to succeed but the
file does not need to stay open after the memory has been mapped.
When the <a href="qfile.html">QFile</a> is destroyed or a new file
is opened with this object, any maps that have not been unmapped
will automatically be unmapped.</p>
<p>Any mapping options can be passed through <i>flags</i>.</p>
<p>Returns a pointer to the memory or 0 if there is an error.</p>
<p><b>Note:</b> On Windows CE 5.0 the file will be closed before
mapping occurs.</p>
<p>This function was introduced in Qt 4.4.</p>
<p><b>See also</b> <a href="qfile.html#unmap">unmap</a>() and
<a href="qabstractfileengine.html#supportsExtension">QAbstractFileEngine.supportsExtension</a>().</p>


<h3 class="fn"><a name="open" />bool QFile.open (<i>self</i>, <a href="qiodevice-openmode.html">QIODevice.OpenMode</a>&#160;<i>flags</i>)</h3><p>Reimplemented from <a href="qiodevice.html#open">QIODevice.open</a>().</p>
<p>Opens the file using <a href="qiodevice.html#OpenModeFlag-enum">OpenMode</a> <i>mode</i>,
returning true if successful; otherwise false.</p>
<p>The <i>mode</i> must be <a href="qiodevice.html#OpenModeFlag-enum">QIODevice.ReadOnly</a>,
<a href="qiodevice.html#OpenModeFlag-enum">QIODevice.WriteOnly</a>,
or <a href="qiodevice.html#OpenModeFlag-enum">QIODevice.ReadWrite</a>. It may
also have additional flags, such as <a href="qiodevice.html#OpenModeFlag-enum">QIODevice.Text</a> and <a href="qiodevice.html#OpenModeFlag-enum">QIODevice.Unbuffered</a>.</p>
<p><b>Note:</b> In <a href="qiodevice.html#OpenModeFlag-enum">WriteOnly</a> or <a href="qiodevice.html#OpenModeFlag-enum">ReadWrite</a> mode, if the
relevant file does not already exist, this function will try to
create a new file before opening it.</p>
<p><b>See also</b> <a href="qiodevice.html#OpenModeFlag-enum">QIODevice.OpenMode</a> and
<a href="qfile.html#setFileName">setFileName</a>().</p>


<h3 class="fn"><a name="open-2" />bool QFile.open (<i>self</i>, int&#160;<i>fd</i>, <a href="qiodevice-openmode.html">QIODevice.OpenMode</a>&#160;<i>flags</i>)</h3><h3 class="fn"><a name="permissions" /><a href="qfile-permissions.html">Permissions</a> QFile.permissions (<i>self</i>)</h3><p>Returns the complete OR-ed together combination of <a href="qfile.html#Permission-enum">QFile.Permission</a> for the
file.</p>
<p><b>See also</b> <a href="qfile.html#setPermissions">setPermissions</a>() and <a href="qfile.html#setFileName">setFileName</a>().</p>


<h3 class="fn"><a name="permissions-2" /><a href="qfile-permissions.html">Permissions</a> QFile.permissions (QString&#160;<i>filename</i>)</h3><p>This is an overloaded function.</p>
<p>Returns the complete OR-ed together combination of <a href="qfile.html#Permission-enum">QFile.Permission</a> for
<i>fileName</i>.</p>


<h3 class="fn"><a name="pos" />int QFile.pos (<i>self</i>)</h3><p>Reimplemented from <a href="qiodevice.html#pos">QIODevice.pos</a>().</p>


<h3 class="fn"><a name="readData" />str QFile.readData (<i>self</i>, int&#160;<i>maxlen</i>)</h3><p>Reimplemented from <a href="qiodevice.html#readData">QIODevice.readData</a>().</p>


<h3 class="fn"><a name="readLineData" />str QFile.readLineData (<i>self</i>, int&#160;<i>maxlen</i>)</h3><p>Reimplemented from <a href="qiodevice.html#readLineData">QIODevice.readLineData</a>().</p>


<h3 class="fn"><a name="readLink" />QString QFile.readLink (<i>self</i>)</h3><h3 class="fn"><a name="readLink-2" />QString QFile.readLink (QString&#160;<i>fileName</i>)</h3><h3 class="fn"><a name="remove" />bool QFile.remove (<i>self</i>)</h3><p>Removes the file specified by <a href="qfile.html#fileName">fileName</a>(). Returns true if successful;
otherwise returns false.</p>
<p>The file is closed before it is removed.</p>
<p><b>See also</b> <a href="qfile.html#setFileName">setFileName</a>().</p>


<h3 class="fn"><a name="remove-2" />bool QFile.remove (QString&#160;<i>fileName</i>)</h3><p>This is an overloaded function.</p>
<p>Removes the file specified by the <i>fileName</i> given.</p>
<p>Returns true if successful; otherwise returns false.</p>
<p><b>See also</b> <a href="qfile.html#remove">remove</a>().</p>


<h3 class="fn"><a name="rename" />bool QFile.rename (<i>self</i>, QString&#160;<i>newName</i>)</h3><p>Renames the file currently specified by <a href="qfile.html#fileName">fileName</a>() to <i>newName</i>. Returns
true if successful; otherwise returns false.</p>
<p>If a file with the name <i>newName</i> already exists, rename()
returns false (i.e., <a href="qfile.html">QFile</a> will not
overwrite it).</p>
<p>The file is closed before it is renamed.</p>
<p><b>See also</b> <a href="qfile.html#setFileName">setFileName</a>().</p>


<h3 class="fn"><a name="rename-2" />bool QFile.rename (QString&#160;<i>oldName</i>, QString&#160;<i>newName</i>)</h3><p>This is an overloaded function.</p>
<p>Renames the file <i>oldName</i> to <i>newName</i>. Returns true
if successful; otherwise returns false.</p>
<p>If a file with the name <i>newName</i> already exists, <a href="qfile.html#rename">rename</a>() returns false (i.e., <a href="qfile.html">QFile</a> will not overwrite it).</p>
<p><b>See also</b> <a href="qfile.html#rename">rename</a>().</p>


<h3 class="fn"><a name="resize" />bool QFile.resize (<i>self</i>, int&#160;<i>sz</i>)</h3><p>Sets the file size (in bytes) <i>sz</i>. Returns true if the
file if the resize succeeds; false otherwise. If <i>sz</i> is
larger than the file currently is the new bytes will be set to 0,
if <i>sz</i> is smaller the file is simply truncated.</p>
<p><b>See also</b> <a href="qfile.html#size">size</a>() and
<a href="qfile.html#setFileName">setFileName</a>().</p>


<h3 class="fn"><a name="resize-2" />bool QFile.resize (QString&#160;<i>filename</i>, int&#160;<i>sz</i>)</h3><p>This is an overloaded function.</p>
<p>Sets <i>fileName</i> to size (in bytes) <i>sz</i>. Returns true
if the file if the resize succeeds; false otherwise. If <i>sz</i>
is larger than <i>fileName</i> currently is the new bytes will be
set to 0, if <i>sz</i> is smaller the file is simply truncated.</p>
<p><b>See also</b> <a href="qfile.html#resize">resize</a>().</p>


<h3 class="fn"><a name="seek" />bool QFile.seek (<i>self</i>, int&#160;<i>offset</i>)</h3><p>Reimplemented from <a href="qiodevice.html#seek">QIODevice.seek</a>().</p>
<p>For random-access devices, this function sets the current
position to <i>pos</i>, returning true on success, or false if an
error occurred. For sequential devices, the default behavior is to
do nothing and return false.</p>
<p>Seeking beyond the end of a file: If the position is beyond the
end of a file, then seek() shall not immediately extend the file.
If a write is performed at this position, then the file shall be
extended. The content of the file between the previous end of file
and the newly written data is UNDEFINED and varies between
platforms and file systems.</p>
<p>This function was introduced in Qt 4.8.</p>


<h3 class="fn"><a name="setFileName" />QFile.setFileName (<i>self</i>, QString&#160;<i>name</i>)</h3><p>Sets the <i>name</i> of the file. The name can have no path, a
relative path, or an absolute path.</p>
<p>Do not call this function if the file has already been
opened.</p>
<p>If the file name has no path or a relative path, the path used
will be the application's current directory path <i>at the time of
the <a href="qfile.html#open">open</a>()</i> call.</p>
<p>Example:</p>
<pre class="cpp">
 <span class="type"><a href="qfile.html">QFile</a></span> file;
 <span class="type"><a href="qdir.html">QDir</a></span><span class="operator">.</span>setCurrent(<span class="string">"/tmp"</span>);
 file<span class="operator">.</span>setFileName(<span class="string">"readme.txt"</span>);
 <span class="type"><a href="qdir.html">QDir</a></span><span class="operator">.</span>setCurrent(<span class="string">"/home"</span>);
 file<span class="operator">.</span><a href="qfile.html#open">open</a>(<span class="type"><a href="qiodevice.html">QIODevice</a></span><span class="operator">.</span>ReadOnly);      <span class="comment">// opens "/home/readme.txt" under Unix</span>
</pre>
<p>Note that the directory separator "/" works for all operating
systems supported by Qt.</p>
<p><b>See also</b> <a href="qfile.html#fileName">fileName</a>(),
<a href="qfileinfo.html">QFileInfo</a>, and <a href="qdir.html">QDir</a>.</p>


<h3 class="fn"><a name="setPermissions" />bool QFile.setPermissions (<i>self</i>, <a href="qfile-permissions.html">Permissions</a>&#160;<i>permissionSpec</i>)</h3><p>Sets the permissions for the file to the <i>permissions</i>
specified. Returns true if successful, or false if the permissions
cannot be modified.</p>
<p><b>See also</b> <a href="qfile.html#permissions">permissions</a>() and <a href="qfile.html#setFileName">setFileName</a>().</p>


<h3 class="fn"><a name="setPermissions-2" />bool QFile.setPermissions (QString&#160;<i>filename</i>, <a href="qfile-permissions.html">Permissions</a>&#160;<i>permissionSpec</i>)</h3><p>This is an overloaded function.</p>
<p>Sets the permissions for <i>fileName</i> file to
<i>permissions</i>.</p>


<h3 class="fn"><a name="size" />int QFile.size (<i>self</i>)</h3><p>Reimplemented from <a href="qiodevice.html#size">QIODevice.size</a>().</p>
<p>Returns the size of the file.</p>
<p>For regular empty files on Unix (e.g. those in <tt>/proc</tt>),
this function returns 0; the contents of such a file are generated
on demand in response to you calling <a href="qiodevice.html#read">read</a>().</p>


<h3 class="fn"><a name="symLinkTarget" />QString QFile.symLinkTarget (<i>self</i>)</h3><p>Returns the absolute path of the file or directory referred to
by the symlink (or shortcut on Windows) specified by
<i>fileName</i>, or returns an empty string if the <i>fileName</i>
does not correspond to a symbolic link.</p>
<p>This name may not represent an existing file; it is only a
string. <a href="qfile.html#exists">QFile.exists</a>() returns
true if the symlink points to an existing file.</p>
<p>This function was introduced in Qt 4.2.</p>


<h3 class="fn"><a name="symLinkTarget-2" />QString QFile.symLinkTarget (QString&#160;<i>fileName</i>)</h3><p>This is an overloaded function.</p>
<p>Returns the absolute path of the file or directory a symlink (or
shortcut on Windows) points to, or a an empty string if the object
isn't a symbolic link.</p>
<p>This name may not represent an existing file; it is only a
string. <a href="qfile.html#exists">QFile.exists</a>() returns
true if the symlink points to an existing file.</p>
<p>This function was introduced in Qt 4.2.</p>
<p><b>See also</b> <a href="qfile.html#fileName">fileName</a>() and
<a href="qfile.html#setFileName">setFileName</a>().</p>


<h3 class="fn"><a name="unmap" />bool QFile.unmap (<i>self</i>, sip.voidptr&#160;<i>address</i>)</h3><p>Unmaps the memory <i>address</i>.</p>
<p>Returns true if the unmap succeeds; false otherwise.</p>
<p>This function was introduced in Qt 4.4.</p>
<p><b>See also</b> <a href="qfile.html#map">map</a>() and <a href="qabstractfileengine.html#supportsExtension">QAbstractFileEngine.supportsExtension</a>().</p>


<h3 class="fn"><a name="unsetError" />QFile.unsetError (<i>self</i>)</h3><p>Sets the file's error to <a href="qfile.html#FileError-enum">QFile.NoError</a>.</p>
<p><b>See also</b> <a href="qfile.html#error">error</a>().</p>


<h3 class="fn"><a name="writeData" />int QFile.writeData (<i>self</i>, str&#160;<i>data</i>)</h3><p>Reimplemented from <a href="qiodevice.html#writeData">QIODevice.writeData</a>().</p>
<address><hr /><div align="center"><table border="0" cellspacing="0" width="100%"><tr class="address"><td align="left" width="25%">PyQt&#160;4.9.1 for X11</td><td align="center" width="50%">Copyright &#169; <a href="http://www.riverbankcomputing.com">Riverbank&#160;Computing&#160;Ltd</a> and <a href="http://www.qtsoftware.com">Nokia</a> 2011</td><td align="right" width="25%">Qt&#160;4.8.0</td></tr></table></div></address></body></html>